package com.zky.utils;

import cn.dev33.satoken.stp.StpUtil;
import com.zky.domain.dto.LoginRequest;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class UserUtil {
    public static String login(LoginRequest loginRequest) {
        //验证账号密码(假设成功)
        StpUtil.login(loginRequest.getUserName());
        return StpUtil.getTokenValue();
    }
    public static String getUserId() throws Exception {

        Object loginId = StpUtil.getLoginIdDefaultNull();
        if(Objects.isNull(loginId)){
            throw new Exception("用户已过期，请重新登录");
        }
        return loginId.toString();
    }

    public static boolean isLogin() {
        return StpUtil.isLogin();
    }

    public static void logout() {
        StpUtil.logout();
    }

}
